package com.lanju.app.service;

import java.util.Date;

import org.springframework.stereotype.Service;

import com.lanju.app.message.bean.B102Request.AttachBean;
import com.lanju.app.message.bean.B105Request;
import com.lanju.app.message.bean.BaseResponse;
import com.lanju.entity.LanjuAttach;
import com.lanju.entity.Shop;
import com.lanju.entity.User;
import com.lanju.enums.Status;

/**
 * 创建新店铺
 * @author fly
 *
 */
@Service("B105Service")
public class B105Service extends BaseService<B105Request,BaseResponse>{

	@Override
	public BaseResponse doService(B105Request request, User u) throws Exception {
		BaseResponse res = new BaseResponse();		
		Shop shop = new Shop();
		shop.setUserId(request.getToken());
		//如果已经有了同名字的，不让再提交
		
		shop.setName(request.getName());
		shop.setAddress(request.getAddress());
//		shop.setArea(request.getArea());
		shop.setCreatedTime(new Date());
		shop.setTel(request.getTel());
		shop.setContact(request.getContact());
		shop.setType(request.getType());
		shop.setStatus(Status.TODO.getStatus());
		if(request.getAttachs().size()>0){
			shop.setPath(request.getAttachs().get(0).getPath());
		}
		dao.save(shop);
		for(AttachBean bean : request.getAttachs()){
			LanjuAttach attach = new LanjuAttach();
			attach.setFkId(shop.getId());
			attach.setPath(bean.getPath());
			attach.setSeq(bean.getSeq());
			attach.setSuffix(bean.getSuffix());
			attach.setType(LanjuAttach.TYPE_SHOP);
			dao.save(attach);
		}
		res.setSuccess(true);
		return res;
	}
}
